package com.vint.mi;

/**
 *  报数123, 第N个小孩的编号
 */
public class Mi67 {
    public static String solution(String line){
        Integer ret = Integer.parseInt(line);
        Node head = init();
        Node tag = null;
        int i = 0;
        while(head!=null){
            tag = head;
            head = head.next.next.next;
            i++;
            if(i==ret){
                return head.val+"";
            }
            tag.next.next.next = head.next;
            head = tag.next.next;
        }
        return "";
    }

    public static Node init(){
        Node root = new Node(1);
        Node head = root;
        for(int i = 1; i<=500; i++){
            root.next = new Node(i);
            root = root.next;
        }
        root.next = head;
        return head;
    }

    static class Node{
        Node next;
        int val;
        Node(int val){
            this.val = val;
        }
    }
    public static void main(String[] args) {
        System.out.println(solution("1"));
        System.out.println(solution("2"));
        System.out.println(solution("206"));
        System.out.println(solution("311"));
    }
}
